package cn.cainiao.dao.impl;

import cn.cainiao.dao.BaseDao;
import cn.cainiao.dao.IPageDao;
import cn.cainiao.entity.UserInfo;

import java.sql.*;

public class PageDaoImpl implements IPageDao {
    Connection conn = null;
    PreparedStatement pstat = null;
    ResultSet rs = null;
    UserInfo user = null;
    public static String usernameA = null;
    public static String passwordA = null;

    @Override
    /**
     * 登录
     */
    public UserInfo login(String username, String password) {
        conn = BaseDao.getConn();
        String sql="select username,password from agent where username = ? and password = ?";
        try {
            pstat = conn.prepareStatement(sql);
            pstat.setString(1,username);
            pstat.setString(2,password);
            rs=pstat.executeQuery();
            if (rs.next()){
                user=new UserInfo();
                user.setUsername(rs.getString("username"));
                user.setPassword(rs.getString("password"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return user;
    }
}